package com.um.jdy.app.charge.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.charge.entity.dto.PBBuyParams;
import com.um.jdy.app.charge.entity.dto.PBStartParam;
import com.um.jdy.app.charge.entity.vo.OrderItemVO;
import com.um.jdy.app.charge.manager.PBOrderManager;
import com.um.jdy.common.charge.entity.vo.OrderVO;
import com.um.jdy.common.charge.enums.OrderStopReason;
import com.um.springboot.starter.annotation.ActionLogRequired;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author renjunwei
 * @date 2022/1/26
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/order/charge/pb")
@AllArgsConstructor
@Api(tags = "充电订单-充电宝")
public class PBOrderController {

    @Autowired
    PBOrderManager pbOrderManager;

    @SaCheckLogin
    @ApiOperation("开始租借")
    @PostMapping("start")
    public Response start(@RequestBody PBStartParam params) {
        return Response.success(pbOrderManager.startRent(params));
    }


    @SaCheckLogin
    @ApiOperation("买断充电宝")
    @PostMapping("buy")
    public Response buy(@RequestBody PBBuyParams params){
        pbOrderManager.rentFinish(params.getOrderNo(),OrderStopReason.PB.BUYED.name(), null, null, true, false);
        return Response.success();
    }

    @ApiOperation("查询租借中订单")
    @GetMapping("renting/orders")
    public Response<List<OrderVO>> getRentingOrders() {
        return Response.success(pbOrderManager.getRentingOrders());
    }

    @ApiOperation("查询未完成订单")
    @GetMapping("unpaid/orders")
    public Response<List<OrderItemVO>> getUnpaidOrders() {
        return Response.success(pbOrderManager.getUnpaidOrders());
    }


    /**
     * 押金微信支付成功回调
     * @param request
     * @param com_id
     * @return
     */
    @ActionLogRequired
    @RequestMapping("/deposit/wxpay/notify/{com_id}")
    public Response depositWxPayNotify(HttpServletRequest request, @PathVariable String com_id) {
        pbOrderManager.depositWxPayNotify(request, com_id);
        return Response.success();
    }

}
